package com.example.service;

import com.example.dao.YinshidacardInfoDao;
import com.example.entity.*;
import com.example.entity.YinshidacardInfo;
import com.example.vo.YinshidacardInfoVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Service
public class YinshidacardInfoService {

    @Resource
    private YinshidacardInfoDao yinshidacardInfoDao;
	@Resource
    private SigninusersInfoService signinusersInfoService;
    
	
	//kuabiaojisuan3

    public YinshidacardInfo add(YinshidacardInfo yinshidacardInfo) {
        //shangxchxuantupxian
        // 唯一校验
        
      // yinshidacardInfo.setAccount((double) 0);
	  
        yinshidacardInfoDao.insertSelective(yinshidacardInfo);
        return yinshidacardInfo;
    }
	
	public List<Map<String,String>> findByDiqu() {
        return yinshidacardInfoDao.findByDiqu();
    }

    public void delete(Long id) {
        yinshidacardInfoDao.deleteByPrimaryKey(id);
    }

    public void update(YinshidacardInfo yinshidacardInfo) {
        //shangxchxuantupxian
		//youdianzan
        yinshidacardInfoDao.updateByPrimaryKeySelective(yinshidacardInfo);
    }

    public YinshidacardInfo findById(Long id) {
        return yinshidacardInfoDao.selectByPrimaryKey(id);
    }
	
    public List<YinshidacardInfoVo> findAll() {
        return yinshidacardInfoDao.findByDacarddates("all");
    }

    public PageInfo<YinshidacardInfoVo> findPage(String dacarddates, Integer pageNum, Integer pageSize, HttpServletRequest request) {
        PageHelper.startPage(pageNum, pageSize);
		
		List<YinshidacardInfoVo> all=null;
        Account user = (Account) request.getSession().getAttribute("user");
        if (user.getLevel().equals("管理员")) {all = yinshidacardInfoDao.findByDacarddates(dacarddates);}
		if (user.getLevel().equals("注册用户")) {all = yinshidacardInfoDao.findByDacarddateslist2(dacarddates,user.getUsername()); }
        
        
        return PageInfo.of(all);
    }
	
	public PageInfo<YinshidacardInfoVo> findPageqt(String dacarddates, Integer pageNum, Integer pageSize, HttpServletRequest request) {
        PageHelper.startPage(pageNum, pageSize);
		
		List<YinshidacardInfoVo> all=null;
        Account user = (Account) request.getSession().getAttribute("user");
        all = yinshidacardInfoDao.findByDacarddates(dacarddates);
		if (user.getLevel().equals("注册用户")) {all = yinshidacardInfoDao.findByDacarddateslist2(dacarddates,user.getUsername()); }
        
	
	
        
        return PageInfo.of(all);
    }

   // public YinshidacardInfoVo findByUserName(String name) {
//        return yinshidacardInfoDao.findByUsername(name);
//    }

	//yoxulogindenxglu
	
    public void changeStatus(Long id) {
        YinshidacardInfo yinshidacardInfo = yinshidacardInfoDao.selectByPrimaryKey(id);
        if(yinshidacardInfo.getStatus().equals("是")){
            yinshidacardInfo.setStatus("否");
            yinshidacardInfoDao.updateByPrimaryKey(yinshidacardInfo);
        }else if(yinshidacardInfo.getStatus().equals("否")){
            yinshidacardInfo.setStatus("是");
            yinshidacardInfoDao.updateByPrimaryKey(yinshidacardInfo);
        }
    }
	//ddaizdhifu
	//youtixing
	
	
	
	public List<YinshidacardInfo> getBysigninusersDacardby(String dacardby) {
    SigninusersInfo signinusersInfo = signinusersInfoService.findByUsername(dacardby);
    return yinshidacardInfoDao.findBydacardby(signinusersInfo);
    }
    
	
	//xiugaimimazys
	
}
